/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ytmc.uploader;

import java.io.File;
import java.io.IOException;
import ytmc.FileSize;
import ytmc.TimePeriod;
import ytmc.TransferSpeed;

/**
 *
 * @author K
 */
public class UploadTask
{
    private String filePath;
    private FileSize size;
    private String title;
    private VideoCategory category;
    private String tags;
    private String description;
    private int progress;
    private UploadTaskStatus status;
    private TransferSpeed uploadSpeed;
    private TimePeriod remainingTime;

    public String getFilePath()
    {
        return filePath;
    }

    public void setFilePath(String filePath)
    {
        this.filePath = filePath;
    }

    public FileSize getSize()
    {
        return size;
    }

    public void setSize(FileSize size)
    {
        this.size = size;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public VideoCategory getCategory()
    {
        return category;
    }

    public void setCategory(VideoCategory category)
    {
        this.category = category;
    }

    public String getTags()
    {
        return tags;
    }

    public void setTags(String tags)
    {
        this.tags = tags;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public int getProgress()
    {
        return progress;
    }

    public void setProgress(int progress)
    {
        this.progress = progress;
    }

    public UploadTaskStatus getStatus()
    {
        return status;
    }

    public void setStatus(UploadTaskStatus status)
    {
        this.status = status;
    }

    public TransferSpeed getUploadSpeed()
    {
        return uploadSpeed;
    }

    public void setUploadSpeed(TransferSpeed uploadSpeed)
    {
        this.uploadSpeed = uploadSpeed;
    }

    public TimePeriod getRemainingTime()
    {
        return remainingTime;
    }

    public void setRemainingTime(TimePeriod remainingTime)
    {
        this.remainingTime = remainingTime;
    }

    UploadTask(String filePath) throws IOException
    {
        this(filePath, "", VideoCategory.FILM, "", "");
    }

    UploadTask(String filePath, String title, VideoCategory category, String tags, String description) throws IOException
    {
        this.filePath = filePath;
        this.title = title;
        this.category = category;
        this.tags = tags;
        this.description = description;
        validate();

        this.size = new FileSize((new File(filePath)).length());
        this.status = UploadTaskStatus.NOT_STARTED;
        this.progress = 0;
        this.uploadSpeed = new TransferSpeed(0);
        this.remainingTime = new TimePeriod(0);
    }

    private void validate() throws IOException
    {
        File file = new File(filePath);

        if (!file.exists() || !file.isFile() || !file.canRead())
        {
            throw new IOException("Podany plik nie istnieje lub nie nadaję sie do odczytu!");
        }
    }
}
